home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_069 / spool / pathname.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  97 lines

  1. /* pathname.c - expand a file's pathname */
  2.  
  3. /***************************************************************************
  4.  
  5.     ExpandPath - general-purpose function to expand a pathname
  6.  
  7.     Usage:
  8.  
  9.     (void) ExpandPath (shortname, fullname);
  10.  
  11.     By: Tim Holloway
  12.     Date Written: December 25, 1986
  13.     Change History: none
  14.  
  15.     Copyright (C) 1986, by Tim Holloway.  May be freely distributed,
  16.     as long as copyright notice is not removed.
  17.  
  18.     Description: Takes an AmigaDOS filename and expands it to a
  19.     full file path description. I.e: "xxx" to "VOLxxx/yyy/zzz/.../xxx"
  20.     Any legal AmigaDOS filename may be used.  If the name is null,
  21.     returns the path name of the current directory (under 1.2 AmigaDOS,
  22.     at least - this is an undocumented feature of the Lock function).
  23.     If the named file does not exist or an error occurred, returns a
  24.     null string as the expanded pathname.
  25.  
  26. ***************************************************************************/
  27.  
  28. #include "exec/types.h"
  29. #include "exec/memory.h"
  30. #include "libraries/dos.h"
  31.  
  32. struct FileInfoBlock fib;
  33.  
  34. typedef ULONG LOCK;
  35.  
  36. static int
  37. parent_name(xlock, longname)
  38. LOCK xlock;
  39. char *longname;
  40. {
  41.     LOCK ylock;
  42.     register int i, j;
  43.  
  44.     ylock = ParentDir (xlock);
  45.     if (ylock == 0) return 0;
  46.  
  47.     i = parent_name(ylock, longname);
  48.     if (!Examine(ylock, &fib))
  49.     {
  50.         return 0;
  51.     }
  52.     strcpy (longname+i, fib.fib_FileName);
  53.     j = i+strlen(fib.fib_FileName);
  54.     if (i == 0)
  55.         longname[j++] = ':';  /* root directory is special */
  56.     else
  57.         longname[j++] = '/';
  58.     UnLock (ylock);
  59.  
  60. /*  printf ("Concatenated to create %s\n", longname); */
  61.     return j;
  62. }
  63.  
  64. ExpandPath(shortname, longname)
  65. char *shortname, *longname;
  66. {
  67.     register int i;
  68.     LOCK pathlock;
  69.  
  70.     longname[0] = '\0';
  71.     if ( (pathlock=Lock(shortname, ACCESS_READ)) == 0)
  72.     {
  73.         return;
  74.     }
  75.  
  76.     i = parent_name(pathlock, longname);    
  77.     if (!Examine(pathlock, &fib))
  78.     {
  79.         return;
  80.     }
  81.     strcpy (longname+i, fib.fib_FileName);
  82.     UnLock (pathlock);
  83. }
  84.  
  85. #ifdef TESTMODE
  86. main(argc, argv)
  87. int argc;
  88. char *argv[];
  89. {
  90.     char full_name[128];
  91.  
  92.     printf ("expand pathname: %s\n", argv[1]);
  93.     ExpandPath(argv[1], full_name);
  94.     printf ("expanded name is '%s'\n", full_name);
  95. }
  96. #endif
  97.